﻿<controls:MetroWindow
    xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="TinyRadio.UserInterface.Views.RadioPlayerWindow"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:local="clr-namespace:TinyRadio.UserInterface"
    xmlns:ioc="clr-namespace:TinyRadio.UserInterface.Infrastructure"
    Title="Tiny Radio"
    SaveWindowPosition="True"
    ShowTitleBar="False"
    ResizeMode="CanMinimize"
    MinWidth="420"
    Width="420"
    MaxWidth="420"
    MinHeight="170"
    Height="170"
    MaxHeight="170"
    Background="#FF2F2F2F"
    Icon="/TinyRadio;component/Resources/Images/Radio.ico">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Resources/Styles/Metro.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <ioc:ServiceLocator x:Key="ServiceLocator" />

            <!-- Radio Station Template -->
            <DataTemplate x:Key="FavoriteRadioStationTemplate">
                <Grid Height="Auto" Width="Auto">
                    <TextBlock Text="{Binding Name}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" />
                    <Button x:Name="tinyRemoveButton"
                            Command="{Binding DataContext.RemoveFavoriteRadioStation, RelativeSource={RelativeSource AncestorType=ListBox}}"
                            CommandParameter="{Binding Content, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                            Visibility="Hidden"
                            HorizontalAlignment="Left">
                        <Button.Template>
                            <ControlTemplate>
                                <Image Source="/Resources/Images/close.png" />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </Grid>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsMouseOver,RelativeSource={RelativeSource TemplatedParent}}"
                                 Value="True">
                        <Setter Property="Visibility" TargetName="tinyRemoveButton" Value="Visible" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate x:Key="RadioStationTemplate">
                <Grid Height="Auto" Width="Auto">
                    <TextBlock Text="{Binding Name}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" />
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <Button x:Name="tinyAddButton" Margin="2"
                                Command="{Binding DataContext.AddRadioStationToFavoritesCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
                                CommandParameter="{Binding Content, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                Visibility="Hidden">
                            <Image Source="/Resources/Images/add.png" />
                        </Button>
                        <!--<Button x:Name="tinyPlayButton" Margin="2"
                                Command="{Binding DataContext.AddRadioStationToFavoritesCommand, RelativeSource={RelativeSource AncestorType=ListBox}}"
                                CommandParameter="{Binding Content, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                Visibility="Hidden">
                            <Image Source="/Resources/Images/play.png" />
                        </Button>-->
                    </StackPanel>
                </Grid>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsSelected,RelativeSource={RelativeSource TemplatedParent}}"
                                 Value="True">
                        <Setter Property="Visibility" TargetName="tinyAddButton" Value="Visible" />
                        <!--<Setter Property="Visibility" TargetName="tinyPlayButton" Value="Visible" />-->
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

        </ResourceDictionary>
    </Window.Resources>

    <Window.DataContext>
        <Binding Path="RadioPlayerViewModel" Source="{StaticResource ServiceLocator}"></Binding>
    </Window.DataContext>

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding CloseCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <controls:MetroWindow.WindowCommands>
        <controls:WindowCommands>
            <Button Content="הגדרות" Click="SettingsWindowCommand_OnClick" />
            <Button Content="תחנות רדיו" Click="RadioStationsWindowCommand_OnClick" />
            <Button Content="נגן" Click="PlayerWindowCommand_OnClick" />
        </controls:WindowCommands>
    </controls:MetroWindow.WindowCommands>

    <Grid>
        <Label Content="Tiny Radio" Margin="3" HorizontalAlignment="Left" VerticalAlignment="Top" />

        <TabControl x:Name="TabControl">
            <TabItem>
                <Grid Margin="0,13,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <StackPanel Grid.Column="0">
                        <StackPanel HorizontalAlignment="Center" Margin="0,7,0,0">
                            <StackPanel x:Name="ControlButtonsStackPanel" Orientation="Horizontal" Height="48"
                                        Width="Auto">
                                <Button BorderBrush="{x:Null}" Margin="2" Visibility="Hidden">
                                    <Image Source="/Resources/Images/appbar.control.rewind.png" />
                                </Button>
                                <Button Command="{Binding PlayCommand}" BorderBrush="{x:Null}" Margin="2">
                                    <Image Source="/Resources/Images/appbar.control.play.png" />
                                </Button>
                                <Button Command="{Binding PauseCommand}" BorderBrush="{x:Null}" Margin="2">
                                    <Image Source="/Resources/Images/appbar.control.pause.png" />
                                </Button>
                                <Button Command="{Binding StopCommand}" BorderBrush="{x:Null}" Margin="2">
                                    <Image Source="/Resources/Images/appbar.control.stop.png" />
                                </Button>
                                <Button BorderBrush="{x:Null}" Margin="2" Visibility="Hidden">
                                    <Image Source="/Resources/Images/appbar.control.fastforward.png" />
                                </Button>
                            </StackPanel>
                            <Slider Value="{Binding Volume}" ToolTip="Volume" Margin="13,0,13,0" d:IsLocked="True" />
                        </StackPanel>
                        <Label Content="{Binding CurrentlyPlayingRadioStation.Name}" HorizontalAlignment="Center"
                               Margin="3" />
                        <TextBlock Text="{Binding State}" HorizontalAlignment="Center" />
                    </StackPanel>

                    <ListBox Grid.Column="1"
                             ItemsSource="{Binding FavoriteRadioStations, IsAsync=True}"
                             ItemTemplate="{DynamicResource FavoriteRadioStationTemplate}"
                             SelectedItem="{Binding SelectedFavoriteRadioStation}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseDoubleClick">
                                <i:InvokeCommandAction Command="{Binding PlayRadioStationCommand}"
                                                       CommandParameter="{Binding SelectedFavoriteRadioStation}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ListBox>
                </Grid>
            </TabItem>

            <TabItem>
                <Grid>
                    <TextBlock DockPanel.Dock="Top" Text="הגדרות" HorizontalAlignment="Right" VerticalAlignment="Top"
                               Margin="0,15,17,5" FontSize="16" />
                </Grid>
            </TabItem>

            <TabItem IsSelected="{Binding IsSelected, Mode=TwoWay, IsAsync=True}">
                <Grid>
                    <controls:ProgressRing IsActive="{Binding IsActive}" />
                    <DockPanel>
                        <TextBlock DockPanel.Dock="Top" Text="תחנות רדיו" HorizontalAlignment="Right"
                                   VerticalAlignment="Top" Margin="0,15,17,5" FontSize="16" />
                        <ListBox DockPanel.Dock="Top"
                                 ItemsSource="{Binding RadioStations, IsAsync=True}"
                                 ItemTemplate="{DynamicResource RadioStationTemplate}"
                                 SelectedItem="{Binding SelectedRadioStation}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="MouseDoubleClick">
                                    <i:InvokeCommandAction Command="{Binding PlayRadioStationCommand}"
                                                           CommandParameter="{Binding SelectedRadioStation}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </ListBox>
                    </DockPanel>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</controls:MetroWindow>